package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppGuildTeam;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Repository
public class GuildTeamDao extends BaseDao<AppGuildTeam> {

    /**
     * 查询列表
     */
    public List<AppGuildTeam> list(Map<String, Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_guild_team where 1=1  ");
        if (StringEx.isNotNull(paraMap.get("startDate"))) {
            sbStr.append(" and DATE_FORMAT(createtime, '%Y-%m-%d')  >=  ? ");
            paramList.add(paraMap.get("startDate"));
        }
        if (StringEx.isNotNull(paraMap.get("endDate"))) {
            sbStr.append(" and DATE_FORMAT(createtime, '%Y-%m-%d')  <=  ? ");
            paramList.add(paraMap.get("endDate"));
        }
        if (StringEx.isNotNull(paraMap.get("teamName"))) {
            sbStr.append(" and teamName like ? ");
            paramList.add("%" + paraMap.get("teamName") + "%");
        }
        if (StringEx.isNotNull(paraMap.get("nick"))) {
            sbStr.append(" and nick like ? ");
            paramList.add("%" + paraMap.get("nick") + "%");
        }
        if (StringEx.isNotNull(paraMap.get("id"))) {
            sbStr.append(" and id = ? ");
            paramList.add(paraMap.get("id"));
        }
        sbStr.append(" order by createtime desc");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppGuildTeam.class, splitPage);
    }

    public List<AppGuildTeam> list(Map<String, Object> paraMap) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_guild_team where 1=1  ");

        sbStr.append(" order by createtime desc");
        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppGuildTeam.class);
    }

    public List<AppGuildTeam> teamCount() {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_guild_team where 1=1  ");

        String sql = sbStr.toString();
        return this.queryList(sql, paramList, AppGuildTeam.class);
    }


    /**
     * 详情
     */
    public AppGuildTeam get(Integer id) {
        if (id == null || id <= 0) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_guild_team where  id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppGuildTeam.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppGuildTeam param) {
        if (param != null && param.getId() != null && param.getId() > 0) {
            this.update(param);
        } else {
            param.setId(this.add(param));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id <= 0) {
            return;
        }
        String sql = "delete  from app_guild_team where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
     * 查询会长的公会信息
     *
     * @param userId
     * @return
     */
    public AppGuildTeam findByUserId(Integer userId) {
        List<Object> paramList = new ArrayList<>();
        StringBuilder sbStr = new StringBuilder("select * from app_guild_team where userId = ? ");
        paramList.add(userId);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppGuildTeam.class);
    }
}
